<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="${ctx}/channel/adjustlist">通道调整</a></li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<form action="${ctx}/channel/adjustlist" method="get" id="listForm">
				<div class="box-header">
					<div class="row RowSearchWork">
						<div class="col-sm-12">
							<div class="col-sm-2">
								<label>代理商：</label>
								<select class="form-control select2" name="agentId">
									<option value="">全部</option>
									<#list agentList as a>
										<#if agentId?exists && a.id == agentId>
											<option value="${a.id}" selected="selected">${a.nickName}</option>
										<#else>
											<option value="${a.id}">${a.nickName}</option>
										</#if>
									</#list>
								</select>
							</div>
						    <div class="col-sm-2">
								<label>线路类型：</label> 
								<select class="form-control" name="channelType">
								   <option value="">全部</option>
								   <#list channelTypeMap as key, value>
										<#if channelType?exists && key == channelType?string>
											<option value="${key}" selected="selected">${value}</option>
										<#else>
											<option value="${key}">${value}</option>
										</#if> 
								   </#list>
								 </select>
							</div>
						    <div class="col-sm-2">
								<label>状态：</label> 
								<select class="form-control" name="channelStatus">
								   <option value="">全部</option>
								   <#list channelStatusMap as key, value>
										<#if channelStatus?exists && key == channelStatus?string>
											<option value="${key}" selected="selected">${value}</option>
										<#else>
											<option value="${key}">${value}</option>
										</#if> 
								   </#list>
								 </select>
							</div>
							<div class="col-sm-2 special-style" style="width: 400px; padding-left: 90px;">
								<label>关键字：</label>
								<select class="form-control" name="keywordType" style="display: inline-block;width: auto;">
									<option value="0" <#if keywordType?? && keywordType == 0>selected="selected"</#if> >--全部--</option>
									<option value="1" <#if keywordType?? && keywordType == 1>selected="selected"</#if> >企业名称</option>
									<option value="2" <#if keywordType?? && keywordType == 2>selected="selected"</#if> >企业ID</option>
									<option value="3" <#if keywordType?? && keywordType == 3>selected="selected"</#if> >登录名</option>
									<option value="4" <#if keywordType?? && keywordType == 4>selected="selected"</#if> >网关标识</option>
									<option value="5" <#if keywordType?? && keywordType == 5>selected="selected"</#if> >外呼号码</option>
									<option value="6" <#if keywordType?? && keywordType == 6>selected="selected"</#if> >IP/TEL</option>
								</select>
								<input name="keyword" type="text" class="form-control" value="${keyword!}" placeholder="请输入关键字" style="display: inline-block;width: 180px;margin-left: 5px;" />
							</div>
							<div class="col-sm-1">
								<input type="button" class="btn btn-default btn-search" onclick="channels.query();" value="查询" />
							</div>
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped table-hide">
						<thead>
							<tr>
								<th width="3%">#</th>
								<th width="9%">外呼号码</th>
								<th width="5%">企业ID</th>
								<th width="8%">企业名称</th>
								<th width="6%">线路类型</th>
								<th width="6%">网关标识</th>
								<th width="8%">IP/TEL</th>
								<th width="5%">卡槽号</th>
								<th width="5%">AI数</th>
								<th width="5%">并发数</th>
								<th width="6%">状态</th>
								<th width="6%">操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as u>
								<tr>
									<td>${page.size * page.number + u_index + 1}</td>
									<td>${u.channelName!}</td>
									<td>${u.companyId!}</td>
									<td>${u.companyName!}</td>
									<td>
										<#if u.channelType?? && channelTypeMap["${u.channelType}"]?? >
											${channelTypeMap["${u.channelType}"]!}
										</#if>
									</td>
									<td>${u.voxGatewayName!}</td>
									<td>${u.channelNum!}</td>
									<td>${u.port!}</td>
									<td>${u.robotNum!}</td>
									<td>${u.concurrentNum!}</td>
									<td>
										<#if u.channelStatus?? && channelStatusMap["${u.channelStatus}"]?? >
											${channelStatusMap["${u.channelStatus}"]!}
										</#if>
									</td>
									<td>
										<a href="javascript:void(0)" onclick="channels.form('${u.channelId}')">编辑</a>&nbsp;&nbsp;
										<a href="javascript:void(0)" onclick="channels.discard('${u.channelId}')">废弃</a>&nbsp;&nbsp;
									</td>
								</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</form>
		</div>
	</section>
</div>

<script type="text/javascript">
function DatePicker($beginSelector, $endSelector) {
	$beginSelector.datepicker({
		language : "zh-CN",
		autoclose : true,
		startView : 0,
		format : "yyyy-mm-dd",
		clearBtn : true,
		todayBtn : false,
		endDate : '${endTime!}'
	}).on('changeDate', function(ev) {
		if (ev.date) {
			$endSelector.datepicker('setStartDate', new Date(ev.date.valueOf()));
		} else {
			$endSelector.datepicker('setStartDate', null);
		}
	});
	
	$endSelector.datepicker({
		language : "zh-CN",
		autoclose : true,
		startView : 0,
		format : "yyyy-mm-dd",
		clearBtn : true,
		todayBtn : false,
		startDate : '${beginTime!}'
	}).on('changeDate', function(ev) {
		if (ev.date) {
			$beginSelector.datepicker('setEndDate', new Date(ev.date.valueOf()));
		} else {
			$beginSelector.datepicker('setEndDate', new Date());
		}
	});
}
// 仅选择日期
DatePicker($("#starTime"), $("#endTime"));


$('.select2').select2();
$.fn.modal.Constructor.prototype.enforceFocus = function() {};

var is_submit=false;

var channels = {
	query : function() {
		$(":input[name='pageNumber']").val(0);
		$("form").submit();
	},
	form : function(channelId) {
		if(is_submit){
			return;
		}
		is_submit=true;
		
		channelId = channelId? channelId : "";
		var title = "编辑通道";
		var j = 0;
		base.getView({
			url:"${ctx}/channel/adjustform?channelId="+channelId,
			success:function(result){
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						cancel:{
							label:"取消",
							className:"btn btn-secondary",
							callback:function(){
								is_submit=false;
							}
						},
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function() {
								if (j != 0) {
									is_submit=false;
									return ;
								}
								j++;
								base.validAndAjaxSubmit($("#editChannel"), $("#listForm"), function () {
									j = 0;
								});
								return false;
							}
						}
					}
				})
			}
		});
	}, 
	discard : function (channelId) {
		if(is_submit){
			return;
		}
		is_submit=true;
		// console.log('channelId='+channelId);
		bootbox.confirm("确定要废弃此通道吗？", function (result) {
			if (result) {
				var verificationPassed = false;
				$.ajax({
					url : "${ctx}/channel/discard",
					type : 'post',
					dataType : 'json',
					async : false,
					data : {"channelId" : channelId},
					success : function(data) {
						if (data.result == 'success') {
							verificationPassed = true;
							$("#listForm").submit();
						}
					}
				});
			}
			is_submit=false;
		});
	}
}
</script>
<#include "../common/footer.htm">